import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import './assets/main.css'
import axios from 'axios'
import { ElMessage } from 'element-plus'

axios.interceptors.response.use((resp) => {
	//将收到的token保存下来。
	if (resp.headers.authorization) {
		localStorage.setItem("token", resp.headers.authorization);
	}
	switch (resp.data.code) {
		case 301:
		case 302:
		case 303:
		case 502:
		case 503:
			ElMessage.error(resp.data.msg);
			break;
		case 899:
			ElMessage.error("用户当前没有操作权限。");
			return Promise.reject("用户当前没有操作权限。");
		case 900: //当收到未登录异常时的处理
			user.logout();
			localStorage.removeItem("token");
			ElMessage.error("用户未登录。 ");
			return Promise.reject("用户未登录。");
		case 898:
			ElMessage.error("用户名或密码错误");
			return Promise.reject("用户名或密码错误");
	}
	return resp;
});

axios.interceptors.request.use((config) => {
	//每一次请求带着token上去。
	if (localStorage.getItem("token")) config.headers.Authorization = localStorage.getItem("token");

	return config;
});









const app = createApp(App)

app.use(router)
app.use(ElementPlus)

app.mount('#app')

